php Implementation Method Example for Generating PDF Files [Based on FPDF Class Library]

  • 2021-10-24 19:15:16
  • OfStack

In this paper, an example is given to describe the method of generating PDF files by php implementation. Share it for your reference, as follows:

First, download FPDF http://www.fpdf.org/

Or click here to download it.

Example: Save the following file in the web root directory at the same level as the attachment fpdf17


<?php
ini_set('display_errors', '0');
ini_set('max_execution_time', '60');
require ('fpdf17/chinese.php');
$pdf = new PDF_Chinese();
$pdf->AddGBFont();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('GB', 'B', 10);
$pdf->SetLeftMargin(15.0);
$pdf->Cell(180, 8, iconv("UTF-8", "gbk", "2015 Year 10 Monthly attendance statistics   Export time : 2015-10-14  Marketing Department 3 People "), 1, 0, 'C');
$pdf->Ln();
// The above is the header 
$pdf->SetFont('GB', '', 8);
$pdf->SetLeftMargin(15.0);
$pdf->Cell(10, 8, iconv("UTF-8", "gbk", "UID"), 1, 0, 'C');
$pdf->Cell(10, 8, iconv("UTF-8", "gbk", " Name "), 1, 0, 'C');
$pdf->Cell(10, 8, iconv("UTF-8", "gbk", " Department "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Attendance / Days "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Attendance / Hours "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Be late / Times "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Be late / Minutes "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Leave early / Times "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Leave early / Times "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Leave early / Minutes "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Missing card / Times "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Location anomaly / Times "), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", " Account status "), 1, 0, 'C');
$pdf->Ln();
$pdf->Cell(10, 8, iconv("UTF-8", "gbk", "10002"), 1, 0, 'C');
$pdf->Cell(10, 8, iconv("UTF-8", "gbk", " Marketing Department "), 1, 0, 'C');
$pdf->Cell(10, 8, iconv("UTF-8", "gbk", "1"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "9.0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Cell(15, 8, iconv("UTF-8", "gbk", "0"), 1, 0, 'C');
$pdf->Ln();
$pdf->Output();
?>

For more readers interested in PHP related contents, please check the special topics of this site: "php File Operation Summary", "php Operation office Document Skills Summary (including word, excel, access, ppt)", "PHP Array (Array) Operation Skills Encyclopedia", "PHP Data Structure and Algorithm Tutorial", "php Programming Algorithm Summary", "PHP Mathematical Operation Skills Summary" and "php String (string) Usage Summary"

I hope this article is helpful to everyone's PHP programming.


Related articles: